//
//  NewHotViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2018/2/12.
//  Copyright © 2018年 企友软mac. All rights reserved.
//

#import "NewHotViewController.h"
#import "NewHotViewCell.h"
#import "NewHotAskViewCell.h"
#import "SGQRCodeScanningVC.h"
#import "WWebViewController.h"
#import "HotLbtModel.h"
#import "HotRdtjModel.h"
#import "HotSxbbModel.h"
#import "WbTopModel.h"
#import "UIButton+WebCache.h"
#import "SchoolListViewController.h"
#import "HotRecomViewCell.h"
#import "SearchViewController.h"
#import "SchoolViewController.h"
#import "WTabBar.h"
#import "TakePhotoViewController.h"
#import "TaxInfoViewController.h"
#import "HotKcsdModel.h"
#import "UIImageView+WebCache.h"
#import "VideoDetailViewController.h"
#import "AnswerSortViewController.h"
#import "DiagramViewController.h"
#import "AudioPlayerManage.h"
#import "UIImageView+WebCache.h"
#import "HotRecomModel.h"
#import "NetworkPayViewController.h"
#import "MemberViewController.h"
#import "LoginViewController.h"
#import "CheckNetwork.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "SearchModel.h"
#import "FalgUrlViewController.h"
#import "CheckNetwork.h"

@interface NewHotViewController ()<UITableViewDataSource, UITableViewDelegate, NewHotViewCellDelegate, NewHotAskViewCellDelegate, UIAlertViewDelegate>
{
    int j;
    BOOL isRefrsh;
    NSString *sum;
    UILabel *lbHeadRefrsh;
    UIView *viewContent;
    UIView *bgMebemView;
    NSDictionary *dicChange;
}

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *arrWbtop;
@property (nonatomic, strong)NSMutableArray *arrXttop;
@property (nonatomic, strong)NSMutableArray *arrSxbb;
@property (nonatomic, strong)NSMutableArray *arrLbt;
@property (nonatomic, strong)NSMutableArray *arrTop;
@property (nonatomic, strong)NSMutableArray *arrWbdt;
@property (nonatomic, strong)NSMutableArray *arrRecom;
@property (nonatomic, strong)NewHotViewCell *hotViewCell;

@end

@implementation NewHotViewController

-(void)SYSJPFWNOTICE {
    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    TakePhotoViewController *takePhotoVc = [mainStory instantiateViewControllerWithIdentifier:@"TakePhotoViewController"];
    takePhotoVc.title = @"手机拍服务";
    [self.navigationController pushViewController:takePhotoVc animated:NO];
}

-(void)SYZXYKNOTICE {
    
    NSString *isgjhy =[NSString stringWithFormat:@"%@",[WShareUtil sharedData].dicSession[@"isgjhy"]];
    if ([isgjhy isEqualToString:@"0"]) {//非高级会员
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此功能只对高级会员开放!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [av show];
        return;
        
    }else {
        
        WWebViewController *webVc = [[WWebViewController alloc] init];
        
        NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"kcyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
        NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
        webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
        webVc.strTitle = @"在线约课";
        
        [self.navigationController pushViewController:webVc animated:NO];
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([WShareUtil sharedData].dicSleSymbol) {
        if ([[WShareUtil sharedData].dicSleSymbol[@"symbol"] isEqualToString:Hot_Symbol]) {
            for (int i = 0; i < self.arrXttop.count; i++) {
                if ([[WShareUtil sharedData].dicSleSymbol[@"id"] isEqualToString:[self.arrXttop[i] strId]]) {

                    WbTopModel *wbTopModel = self.arrXttop[i];
                    if ([[WShareUtil sharedData].dicSleSymbol[@"chosen"] boolValue]) {
                        wbTopModel.chosen = @"1";
                    }
                    [self.arrXttop replaceObjectAtIndex:i withObject:wbTopModel];

                    [self.tableView reloadData];
                    [WShareUtil sharedData].dicSleSymbol = nil;
                }
            }
        }
    }

    if ([WShareUtil sharedData].dicBuySymbol) {
        for (int i = 0; i < self.arrXttop.count; i++) {
            if ([[WShareUtil sharedData].dicBuySymbol[@"id"] isEqualToString:[self.arrXttop[i] strId]]) {

                    WbTopModel *wbTopModel = self.arrXttop[i];
                    if ([[WShareUtil sharedData].dicBuySymbol[@"boughten"] boolValue]) {
                        wbTopModel.boughten = @"1";
                    }
                    [self.arrXttop replaceObjectAtIndex:i withObject:wbTopModel];

                    [self.tableView reloadData];
                    [WShareUtil sharedData].dicBuySymbol = nil;
            }
        }
    }

}

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SYSJPFWNOTICE) name:@"SYSJPFW" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SYZXYKNOTICE) name:@"SYZXYK" object:nil];
    
    _arrWbtop = [NSMutableArray array];
    _arrXttop = [NSMutableArray array];
    _arrSxbb = [NSMutableArray array];
    _arrLbt = [NSMutableArray array];
    _arrTop = [NSMutableArray array];
    _arrWbdt = [NSMutableArray array];
    _arrRecom = [NSMutableArray array];
    
    [self.view addSubview:self.tableView];
    [self.tableView.superview insertSubview:[UIView new] atIndex:0];

    j = 1;
//    NSString *num = [NSString stringWithFormat:@"%d",j];
//    [self hotVcDataRequestNum:num];

        // 获取数据方法
    NSDictionary *returnDic = [WShareUtil getDataWithUserDefaultsForKey: @"newHotList"];
    [self analysisDataDic:returnDic];

    [self notifyRequestListData];
    [self.tableView.header beginRefreshing];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noWifiRefershingEnd) name:NOREFRESH object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyRequestListData) name:HOME_HOT_NOTIFY object:nil];

    _hotViewCell = [[[NSBundle mainBundle] loadNibNamed:@"NewHotViewCell" owner:self options:nil] lastObject];

    lbHeadRefrsh = [[UILabel alloc] init];
    lbHeadRefrsh.textAlignment = NSTextAlignmentCenter;
    lbHeadRefrsh.backgroundColor = WColorFromHexToRGB(0xfff2d8);
    lbHeadRefrsh.frame = CGRectMake(0, 0, WSCREENH_WIDTH, 35);
    lbHeadRefrsh.font = [UIFont systemFontOfSize:15];

    self.tableView.tableHeaderView = lbHeadRefrsh;

    [self requestWdjf];
}

- (void)delegatFlagAppUrlBtnClick {
    FalgUrlViewController *falgUrlVc = [[FalgUrlViewController alloc] init];
    [self.navigationController pushViewController:falgUrlVc animated:YES];
}

- (void)noWifiRefershingEnd {
    [self.tableView.header endRefreshing];
    [self.tableView.footer endRefreshing];
    [WShareUtil sharedData].isShowWait = YES;
}

- (void)notifyRequestListData{
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

        if ([WShareUtil sharedData].isFristStart) {
            [WShareUtil sharedData].isFristStart = NO;
            NSString *num = [NSString stringWithFormat:@"%d",j];
            [self hotVcDataRequestNum:num];
        } else {
            NSString *num = [NSString stringWithFormat:@"%d",++j];
            [self hotVcDataRequestNum:num];
//            [self hotVcDataRequestStrNum:@"1" isRefrsh:YES];
        }
    }];

    self.tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        NSString *num = [NSString stringWithFormat:@"%d",++j];
        [self hotVcDataRequestStrNum:num isRefrsh:NO];
    }];
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT - 64 - 44 - 49 ) style:UITableViewStylePlain];
        self.tableView.estimatedRowHeight =0;
        self.tableView.estimatedSectionHeaderHeight =0;
        self.tableView.estimatedSectionFooterHeight =0;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//去掉横线
    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return self.arrRecom.count;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        return 635;

    } else if (indexPath.section == 1) {

        if (iPhone5SE) {
            return 635;
        } else {
            return 650;
        }
        
    } else {
        if (indexPath.row == 0) {
            return 130;
        }
        return 110;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HOTCELL"];

    if (indexPath.section == 0) {
        if (cell == nil) {
            _hotViewCell = [[[NSBundle mainBundle] loadNibNamed:@"NewHotViewCell" owner:self options:nil] lastObject];
            _hotViewCell.arrayOfAds = _arrLbt;
            if (_arrTop != nil && _arrTop.count > 0) {
                _hotViewCell.lbTopTitle.text = [_arrTop[0] strTitle];

                _hotViewCell.lbTopSource.text = [_arrTop[0] wzly];
          
                CGSize maximumLbTitle = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSize = [_hotViewCell.lbTopSource sizeThatFits:maximumLbTitle];
                _hotViewCell.widthCon.constant = expectSize.width;

                NSString *topNum = [NSString stringWithFormat:@"%@人看过",[_arrTop[0] strView]];
                _hotViewCell.lbTopNum.text = topNum;

                CGSize maximumLbTop = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSizeTop = [_hotViewCell.lbTopNum sizeThatFits:maximumLbTop];
                _hotViewCell.numWidthCon.constant = expectSizeTop.width;

                _hotViewCell.lbTopDate.text = [_arrTop[0] fbsj];
//                [_hotViewCell.imgTop sd_setImageWithURL:[NSURL URLWithString:[_arrTop[0] imgsrc]] placeholderImage:nil];

//                GifView *gifView = [WShareUtil animatedGifWithData:_hotViewCell.imgTop];
                GifView *gifView = [WShareUtil animatedGifWithDataSize:CGSizeMake(WSCREENH_WIDTH, 100)];
                [_hotViewCell.imgTop addSubview:gifView];

                if ([WShareUtil strNilOrEmpty:[self.arrTop[0] link]]) {
                    if ([[_arrTop[0] chosen] boolValue]) {
                        _hotViewCell.lbTypeT.hidden = NO;
                        _hotViewCell.lbTypeT.text = @"已选课";
                        _hotViewCell.lbTypeT.backgroundColor = WRGBColor(235, 107, 12);
                    } else if (![[_arrTop[0] chosen] boolValue] && [[_arrTop[0] boughten] boolValue]) {
                        _hotViewCell.lbTypeT.hidden = NO;
                        _hotViewCell.lbTypeT.text = @"已购买";
                        _hotViewCell.lbTypeT.backgroundColor = WRGBColor(208, 45, 39);
                    }
                }

                [_hotViewCell.imgTop sd_setImageWithURL:[NSURL URLWithString:[_arrTop[0] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView removeFromSuperview];
                }];

            }

            if (_arrSxbb != nil && _arrSxbb.count > 0) {
                _hotViewCell.lbPolicy.text = [_arrSxbb[0] strTitle];
                NSString *numPolicy = [NSString stringWithFormat:@"%@人看过",[_arrSxbb[0] strView]];
                _hotViewCell.lbPolicyNum.text = numPolicy;
                CGSize maximumLbTitle = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSize = [_hotViewCell.lbPolicyNum sizeThatFits:maximumLbTitle];
                _hotViewCell.widthNewCon.constant = expectSize.width;

                _hotViewCell.lbPolicyTime.text = [_arrSxbb[0] fbsj];
//                [_hotViewCell.imgPolicy sd_setImageWithURL:[NSURL URLWithString:[_arrSxbb[0] imgsrc]] placeholderImage:nil];

                GifView *gifView = [WShareUtil animatedGifWithData:_hotViewCell.imgPolicy];
                [_hotViewCell.imgPolicy addSubview:gifView];

                [_hotViewCell.imgPolicy sd_setImageWithURL:[NSURL URLWithString:[_arrSxbb[0] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView removeFromSuperview];
                }];

                _hotViewCell.lbReport.text = [_arrSxbb[1] strTitle];

                [UILabel changeSpaceForLabel: _hotViewCell.lbReport];
                [UILabel changeSpaceForLabel: _hotViewCell.lbPolicy];

                NSString *numReport = [NSString stringWithFormat:@"%@人看过",[_arrSxbb[1] strView]];
                _hotViewCell.lbReportNum.text = numReport;

                CGSize maximumLbRep = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSizeRep = [_hotViewCell.lbReportNum sizeThatFits:maximumLbRep];
                _hotViewCell.widthRepCon.constant = expectSizeRep.width;

                _hotViewCell.lbReportTime.text = [_arrSxbb[1] fbsj];
//                [_hotViewCell.imgReport sd_setImageWithURL:[NSURL URLWithString:[_arrSxbb[1] imgsrc]] placeholderImage:nil];

                GifView *gifView1 = [WShareUtil animatedGifWithData:_hotViewCell.imgReport];
                [_hotViewCell.imgReport addSubview:gifView1];

                [_hotViewCell.imgReport sd_setImageWithURL:[NSURL URLWithString:[_arrSxbb[1] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView1 removeFromSuperview];
                }];
            }

            _hotViewCell.delegate = self;
            cell = _hotViewCell;
        }
    }else if (indexPath.section == 1) {
        if (cell == nil) {
            NewHotAskViewCell *hotAskViewCell = [[[NSBundle mainBundle] loadNibNamed:@"NewHotAskViewCell" owner:self options:nil] lastObject];

            if (_arrWbtop != nil && _arrWbtop.count > 0) {
                hotAskViewCell.lbAnswerNew.text = [_arrWbtop[0] strTitle];

                hotAskViewCell.lbAnswerNewScoure.text = [_arrWbtop[0] wzly];
                CGSize maximumLbTitle = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSize = [hotAskViewCell.lbAnswerNewScoure sizeThatFits:maximumLbTitle];
                hotAskViewCell.widthCon.constant = expectSize.width;

                NSString *numAskTop = [NSString stringWithFormat:@"%@人看过",[_arrWbtop[0] strView]];
                hotAskViewCell.lbAnswerNewNum.text = numAskTop;

                CGSize maximumLbTop = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSizeTop = [hotAskViewCell.lbAnswerNewNum sizeThatFits:maximumLbTop];
                hotAskViewCell.numWidthCon.constant = expectSizeTop.width;

                hotAskViewCell.lbAnswerNewTime.text = [_arrWbtop[0] fbsj];
//                [hotAskViewCell.imgAnswerNew sd_setImageWithURL:[NSURL URLWithString:[_arrWbtop[0] imgsrc]] placeholderImage:nil];
//                GifView *gifView1 = [WShareUtil animatedGifWithData:hotAskViewCell.imgAnswerNew];
                GifView *gifView1 = [WShareUtil animatedGifWithDataSize:CGSizeMake(WSCREENH_WIDTH, 100)];

                [hotAskViewCell.imgAnswerNew addSubview:gifView1];

                [hotAskViewCell.imgAnswerNew sd_setImageWithURL:[NSURL URLWithString:[_arrWbtop[0] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView1 removeFromSuperview];
                }];

                if ([WShareUtil strNilOrEmpty:[_arrWbtop[0] link]]) {
                    if ([[_arrWbtop[0] chosen] boolValue]) {
                        hotAskViewCell.lbTypeTop.hidden = NO;
                        hotAskViewCell.lbTypeTop.text = @"已选课";
                        hotAskViewCell.lbTypeTop.backgroundColor = WRGBColor(235, 107, 12);
                    } else if (![[_arrWbtop[0] chosen] boolValue] && [[_arrWbtop[0] boughten] boolValue]) {
                        hotAskViewCell.lbTypeTop.hidden = NO;
                        hotAskViewCell.lbTypeTop.text = @"已购买";
                        hotAskViewCell.lbTypeTop.backgroundColor = WRGBColor(208, 45, 39);
                    }
                }

            }

            if (_arrWbdt != nil && _arrWbdt.count > 0) {
                hotAskViewCell.lbAnswerPolicy.text = [_arrWbdt[0] strTitle];
//                [hotAskViewCell.imgAnswerPolicy sd_setImageWithURL:[NSURL URLWithString:[_arrWbdt[0] imgsrc]] placeholderImage:nil];

                GifView *gifView1 = [WShareUtil animatedGifWithData:hotAskViewCell.imgAnswerPolicy];
                [hotAskViewCell.imgAnswerPolicy addSubview:gifView1];

                [hotAskViewCell.imgAnswerPolicy sd_setImageWithURL:[NSURL URLWithString:[_arrWbdt[0] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView1 removeFromSuperview];
                }];

                NSString *numAnswerPolicy = [NSString stringWithFormat:@"%@人看过",[_arrWbdt[0] strView]];
                hotAskViewCell.lbPolicyNum.text = numAnswerPolicy;

                CGSize maximumLbPolicy = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSizePolicy = [hotAskViewCell.lbPolicyNum sizeThatFits:maximumLbPolicy];
                hotAskViewCell.widthNewCon.constant = expectSizePolicy.width;

                hotAskViewCell.lbPolicyTime.text = [_arrWbdt[0] fbsj];

                hotAskViewCell.lbAnswerReport.text = [_arrWbdt[1] strTitle];
                NSString *numAnswerReport = [NSString stringWithFormat:@"%@人看过",[_arrWbdt[1] strView]];
                hotAskViewCell.lbReportNum.text = numAnswerReport;

                CGSize maximumLbReport = CGSizeMake(MAXFLOAT, 16);//labelsize的最大值
                CGSize expectSizeReport = [hotAskViewCell.lbReportNum sizeThatFits:maximumLbReport];
                hotAskViewCell.widthRepCon.constant = expectSizeReport.width;

//                [hotAskViewCell.imgAnswerReport sd_setImageWithURL:[NSURL URLWithString:[_arrWbdt[1] imgsrc]] placeholderImage:nil];

                GifView *gifView = [WShareUtil animatedGifWithData:hotAskViewCell.imgAnswerReport];
                [hotAskViewCell.imgAnswerReport addSubview:gifView];

                [hotAskViewCell.imgAnswerReport sd_setImageWithURL:[NSURL URLWithString:[_arrWbdt[1] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView removeFromSuperview];
                }];

                hotAskViewCell.lbReportTime.text = [_arrWbdt[1] fbsj];

                [UILabel changeSpaceForLabel: hotAskViewCell.lbAnswerReport];
                [UILabel changeSpaceForLabel: hotAskViewCell.lbAnswerPolicy];

            }

            if (_arrXttop != nil && _arrXttop.count > 0) {
                hotAskViewCell.lbKcsdL.text = [_arrXttop[0] strTitle];
//                [hotAskViewCell.imgKcsdLeft sd_setImageWithURL:[NSURL URLWithString:[_arrXttop[0] imgsrc]] placeholderImage:nil];

                if ([WShareUtil strNilOrEmpty:[_arrXttop[0] link]]) {
                    if ([[_arrXttop[0] chosen] boolValue]) {
                        hotAskViewCell.lbTypeL.hidden = NO;
                        hotAskViewCell.lbTypeL.text = @"已选课";
                        hotAskViewCell.lbTypeL.backgroundColor = WRGBColor(235, 107, 12);
                    } else if (![[_arrXttop[0] chosen] boolValue] && [[_arrXttop[0] boughten] boolValue]) {
                        hotAskViewCell.lbTypeL.hidden = NO;
                        hotAskViewCell.lbTypeL.text = @"已购买";
                        hotAskViewCell.lbTypeL.backgroundColor = WRGBColor(208, 45, 39);
                    }
                }

                GifView *gifView = [WShareUtil animatedGifWithData:hotAskViewCell.imgKcsdLeft];
                [hotAskViewCell.imgKcsdLeft addSubview:gifView];

                [hotAskViewCell.imgKcsdLeft sd_setImageWithURL:[NSURL URLWithString:[_arrXttop[0] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView removeFromSuperview];
                }];

                hotAskViewCell.lbKcsdM.text = [_arrXttop[1] strTitle];
//                [hotAskViewCell.imgKcsdMiddle sd_setImageWithURL:[NSURL URLWithString:[_arrXttop[1] imgsrc]] placeholderImage:nil];

                if ([[_arrXttop[1] chosen] boolValue]) {
                    hotAskViewCell.lbTypeM.hidden = NO;
                    hotAskViewCell.lbTypeM.text = @"已选课";
                    hotAskViewCell.lbTypeM.backgroundColor = WRGBColor(235, 107, 12);
                } else if (![[_arrXttop[1] chosen] boolValue] && [[_arrXttop[1] boughten] boolValue]) {
                    hotAskViewCell.lbTypeM.hidden = NO;
                    hotAskViewCell.lbTypeM.text = @"已购买";
                    hotAskViewCell.lbTypeM.backgroundColor = WRGBColor(208, 45, 39);
                }

                GifView *gifView1 = [WShareUtil animatedGifWithData:hotAskViewCell.imgKcsdMiddle];
                [hotAskViewCell.imgKcsdMiddle addSubview:gifView1];

                [hotAskViewCell.imgKcsdMiddle sd_setImageWithURL:[NSURL URLWithString:[_arrXttop[1] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView1 removeFromSuperview];
                }];

                if ([[_arrXttop[2] chosen] boolValue]) {
                    hotAskViewCell.lbTypeR.hidden = NO;
                    hotAskViewCell.lbTypeR.text = @"已选课";
                    hotAskViewCell.lbTypeR.backgroundColor = WRGBColor(235, 107, 12);
                } else if (![[_arrXttop[2] chosen] boolValue] && [[_arrXttop[2] boughten] boolValue]) {
                    hotAskViewCell.lbTypeR.hidden = NO;
                    hotAskViewCell.lbTypeR.text = @"已购买";
                    hotAskViewCell.lbTypeR.backgroundColor = WRGBColor(208, 45, 39);
                }

                hotAskViewCell.lbKcsdR.text = [_arrXttop[2] strTitle];
//                [hotAskViewCell.imgKcsdRight sd_setImageWithURL:[NSURL URLWithString:[_arrXttop[2] imgsrc]] placeholderImage:nil];

                GifView *gifView2 = [WShareUtil animatedGifWithData:hotAskViewCell.imgKcsdRight];
                [hotAskViewCell.imgKcsdRight addSubview:gifView2];

                [hotAskViewCell.imgKcsdRight sd_setImageWithURL:[NSURL URLWithString:[_arrXttop[2] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView2 removeFromSuperview];
                }];
            }
            hotAskViewCell.delegate = self;
            cell = hotAskViewCell;
        }
    } else {
        if (cell == nil) {
            HotRecomViewCell *hotRecomViewCell = [[[NSBundle mainBundle] loadNibNamed:@"HotRecomViewCell" owner:self options:nil] lastObject];

            hotRecomViewCell.spaceCon.constant = 18;

            if (indexPath.row == 0) {
                UILabel *lbRecom = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 150, 20)];
                lbRecom.font = [UIFont systemFontOfSize:17];
                lbRecom.text = @"热点推荐";
                hotRecomViewCell.spaceCon.constant = 10;
                [hotRecomViewCell addSubview:lbRecom];
            }
            if (_arrRecom && _arrRecom.count > 0) {
                hotRecomViewCell.lbTitle.text = [self.arrRecom[indexPath.row] strTitle];
                [UILabel changeSpaceForLabel: hotRecomViewCell.lbTitle];

                GifView *gifView = [WShareUtil animatedGifWithData:hotRecomViewCell.imgCell];
                [hotRecomViewCell.imgCell addSubview:gifView];

                [hotRecomViewCell.imgCell sd_setImageWithURL:[NSURL URLWithString:[self.arrRecom[indexPath.row] imgsrc]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    [gifView removeFromSuperview];
                }];

            }
            cell = hotRecomViewCell;
        }

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)timerAction {
    lbHeadRefrsh.frame = CGRectMake(0, 0, WSCREENH_WIDTH, 0);
    self.tableView.tableHeaderView = lbHeadRefrsh;
    isRefrsh = NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 2) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"热点推荐";

        webVc.shareTitle = [self.arrRecom[indexPath.row] strTitle];//分享标题
        webVc.strID = [self.arrRecom[indexPath.row] strId];//分享ID
        webVc.strType = @"sx";//分享类型税信

        webVc.strUrl = [self.arrRecom[indexPath.row] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }
}

- (void)delegatiCarClick:(NSInteger)index {

    WWebViewController *webVc = [[WWebViewController alloc] init];
    webVc.strTitle = @"热点推荐";
    webVc.strUrl = [_arrLbt[index] link];
    [self.navigationController pushViewController:webVc animated:YES];
}

- (void)delegatBtnClick:(UIButton *)button {
    if (button.tag == 2000) {
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
            TaxInfoViewController *taxInfoVc = [[TaxInfoViewController alloc] init];
            [self.navigationController pushViewController:taxInfoVc animated:YES];
        }

    }else if (button.tag == 2001) {
        if ([WShareUtil strNilOrEmpty:[self.arrTop[0] link]]) {
            VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
            videoDetailVc.strId = [self.arrTop[0] strId];
            videoDetailVc.symbol = Hot_Symbol;
            [self.navigationController pushViewController:videoDetailVc animated:YES];
        } else {
            WWebViewController *webVc = [[WWebViewController alloc] init];
            webVc.strTitle = @"税信";
            webVc.shareTitle = [self.arrTop[0] strTitle];//分享标题
            webVc.strID = [self.arrTop[0] strId];//分享ID
            if ([[self.arrTop[0] wzlx] isEqualToString:@"yp"]) {
                webVc.strType = @"wz";
            }else{
                webVc.strType = [self.arrTop[0] wzlx];
            }
            webVc.strUrl = [self.arrTop[0] link];
            [self.navigationController pushViewController:webVc animated:YES];
        }
    }else if (button.tag == 2002) {

        if (self.arrSxbb != nil && self.arrSxbb.count > 0) {

            if ([WShareUtil strNilOrEmpty:[self.arrSxbb[0] link]]) {

                VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
                videoDetailVc.strId = [self.arrSxbb[0] strId];
                videoDetailVc.symbol = Hot_Symbol;
                [self.navigationController pushViewController:videoDetailVc animated:YES];
            } else {
                WWebViewController *webVc = [[WWebViewController alloc] init];
                webVc.strTitle = @"税信";
                webVc.shareTitle = [self.arrSxbb[0] strTitle];//分享标题
                webVc.strID = [self.arrSxbb[0] strId];//分享ID
                webVc.strUrl = [self.arrSxbb[0] link];
                if ([[self.arrSxbb[0] wzlx] isEqualToString:@"yp"]) {
                    webVc.strType = @"wz";
                }else{
                    webVc.strType = [self.arrSxbb[0] wzlx];
                }

                [self.navigationController pushViewController:webVc animated:YES];
            }
        }

        
    }else if (button.tag == 2003) {

        if (self.arrSxbb != nil && self.arrSxbb.count > 0) {

            if ([WShareUtil strNilOrEmpty:[self.arrSxbb[0] link]]) {

                VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
                videoDetailVc.strId = [self.arrSxbb[1] strId];
                videoDetailVc.symbol = Hot_Symbol;
                [self.navigationController pushViewController:videoDetailVc animated:YES];
            } else {
                WWebViewController *webVc = [[WWebViewController alloc] init];
                webVc.strTitle = @"税信";
                webVc.shareTitle = [self.arrSxbb[1] strTitle];//分享标题
                webVc.strID = [self.arrSxbb[1] strId];//分享ID
                webVc.strUrl = [_arrSxbb[1] link];
                if ([[self.arrSxbb[1] wzlx] isEqualToString:@"yp"]) {
                    webVc.strType = @"wz";
                }else{
                    webVc.strType = [self.arrSxbb[1] wzlx];
                }
                [self.navigationController pushViewController:webVc animated:YES];
            }
        }
    }
}

- (void)delegatAskBtnClick:(UIButton *)button {

    [WShareUtil sharedData].isShowWait = NO;

//    AudioPlayerManage *playerManage = [AudioPlayerManage playerManage];
//    playerManage.delegatePlayer = self;
    if (button.tag == 3000) {
        self.tabBarController.selectedIndex = 2;
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
       [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];

    }else if (button.tag == 3001) {
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"sb";
        [WShareUtil sharedData].strLevel2 = @"tech";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"sb",@"strLevel2":@"tech"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];

    }else if (button.tag == 3002) {
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"kp";
        [WShareUtil sharedData].strLevel2 = @"tech";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"kp",@"strLevel2":@"tech"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];

    }else if (button.tag == 3003) {
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"";
        [WShareUtil sharedData].strLevel2 = @"tax";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"",@"strLevel2":@"tax"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 3004) {
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"";
        [WShareUtil sharedData].strLevel2 = @"note";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"",@"strLevel2":@"note"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 3005) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"大家都在问";

        if (_arrWbtop != nil && _arrWbtop.count > 0) {
            webVc.shareTitle = [self.arrWbtop[0] strTitle];//分享标题
            webVc.strID = [self.arrWbtop[0] strId];//分享ID
            webVc.strUrl = [_arrWbtop[0] link];
            if (![[self.arrWbtop[0] wzlx] isEqualToString:@"sx"]) {
                webVc.strType = @"wz";
            }else{
                webVc.strType = [self.arrWbtop[0] wzlx];
            }
        }

        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 3006) {
        //        [self hotVcSBDataRequest:@"tech" level2:@"sb"];
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"大家都在问";

        if (_arrWbdt != nil && _arrWbdt.count > 0) {
            webVc.shareTitle = [self.arrWbdt[0] strTitle];//分享标题
            webVc.strID = [self.arrWbdt[0] strId];//分享ID
            webVc.strUrl = [_arrWbdt[0] link];
            if (![[self.arrWbdt[0] wzlx] isEqualToString:@"sx"]) {
                webVc.strType = @"wz";
            }else{
                webVc.strType = [self.arrWbdt[0] wzlx];
            }
        }

        [self.navigationController pushViewController:webVc animated:YES];

    }else if (button.tag == 3007) {
        //        [self hotVcSBDataRequest:@"tech" level2:@"kp"];
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"大家都在问";

        if (_arrWbdt != nil && _arrWbdt.count > 0) {
            webVc.shareTitle = [self.arrWbdt[1] strTitle];//分享标题
            webVc.strID = [self.arrWbdt[1] strId];//分享ID
            webVc.strUrl = [_arrWbdt[1] link];
            if (![[self.arrWbdt[1] wzlx] isEqualToString:@"sx"]) {
                webVc.strType = @"wz";
            }else{
                webVc.strType = [self.arrWbdt[1] wzlx];
            }
        }

        [self.navigationController pushViewController:webVc animated:YES];

    }else if (button.tag == 4000) {
        //        [self hotVcSBDataRequest:@"tax" level2:@""];
        SchoolViewController *schoolVc = [[SchoolViewController alloc] init];
        schoolVc.isMore = YES;
        [self.navigationController pushViewController:schoolVc animated:YES];

    }else if (button.tag == 4001) {
        SchoolListViewController *listVc = [[SchoolListViewController alloc]init];
        listVc.title = @"发票管理";
        listVc.strType = @"fpgl";
        [self.navigationController pushViewController:listVc animated:YES];
    }else if (button.tag == 4002) {
        SchoolListViewController *listVc = [[SchoolListViewController alloc]init];
        listVc.title = @"申报及办税";
        listVc.strType = @"wssb";
        [self.navigationController pushViewController:listVc animated:YES];
    }else if (button.tag == 4003) {
        SchoolListViewController *listVc = [[SchoolListViewController alloc]init];
        listVc.title = @"增值税";
        listVc.strType = @"zzsfp";
        [self.navigationController pushViewController:listVc animated:YES];
    }else if (button.tag == 4004) {
        SchoolListViewController *listVc = [[SchoolListViewController alloc]init];
        listVc.title = @"地方税类";
        listVc.strType = @"dfsl";
        [self.navigationController pushViewController:listVc animated:YES];
    }else if (button.tag == 5000) {
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
            VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
            if (_arrXttop != nil && _arrXttop.count > 0) {
                videoDetailVc.strId = [_arrXttop[0] strId];
            }
            videoDetailVc.symbol = Hot_Symbol;
            [self.navigationController pushViewController:videoDetailVc animated:YES];
        }

    }else if (button.tag == 5001) {
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
            VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
            
            if (_arrXttop != nil && _arrXttop.count > 0) {
                videoDetailVc.strId = [_arrXttop[1] strId];
            }
            videoDetailVc.symbol = Hot_Symbol;
            [self.navigationController pushViewController:videoDetailVc animated:YES];
        }

    }else if (button.tag == 5002) {
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
            VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
            if (_arrXttop != nil && _arrXttop.count > 0) {
                videoDetailVc.strId = [_arrXttop[2] strId];
            }
            videoDetailVc.symbol = Hot_Symbol;
            [self.navigationController pushViewController:videoDetailVc animated:YES];
        }

    }else if (button.tag == 10000) {

        button.selected = !button.selected;
        if (button.selected) {

            [button setImage:[UIImage imageNamed:@"listen_pause.png"] forState:UIControlStateNormal];

//            [playerManage audioPlayerPlay];

        }else {
            [button setImage:[UIImage imageNamed:@"hot_playVedio.png"] forState:UIControlStateNormal];
//            [playerManage audioPlayerPause];
        }

    }else if (button.tag == 10001) {
        button.selected = !button.selected;
        if (button.selected) {

            [button setImage:[UIImage imageNamed:@"listen_pause.png"] forState:UIControlStateNormal];

//            [playerManage audioPlayerPlay];

        }else {
            [button setImage:[UIImage imageNamed:@"hot_playVedio.png"] forState:UIControlStateNormal];
//            [playerManage audioPlayerPause];
        }
    }else if (button.tag == 10002) {
        button.selected = !button.selected;
        if (button.selected) {

            [button setImage:[UIImage imageNamed:@"listen_pause.png"] forState:UIControlStateNormal];

//            [playerManage audioPlayerPlay];

        }else {
            [button setImage:[UIImage imageNamed:@"hot_playVedio.png"] forState:UIControlStateNormal];
//            [playerManage audioPlayerPause];
        }
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    AudioPlayerManage *playerManage = [AudioPlayerManage playerManage];
    [playerManage audioPlayerDestroy];
}

- (void)delegatCollectionBtnClick:(NSInteger)tag {
    if (tag == 8) {
        if ([WShareUtil sharedData].dicSession) {

            UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            TakePhotoViewController *takePhotoVc = [mainStory instantiateViewControllerWithIdentifier:@"TakePhotoViewController"];
            takePhotoVc.title = @"手机拍服务";
            [self.navigationController pushViewController:takePhotoVc animated:YES];
            
        }else {
//            [SVProgressHUD showImage:nil status:@"请先登录"];
//            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
//            [SVProgressHUD dismissWithDelay:1.];
//            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];
            
            [WShareUtil sharedData].Who = @"SYSJPFW";
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }
    }else if (tag == 0) {
//        WWebViewController *webVc = [[WWebViewController alloc] init];
//        webVc.strTitle = @"在线客服";
//        webVc.strUrl = @"http://www.sobot.com/chat/pc/index.html?sysNum=79f43fe7ebd049898175758d0b00d986";
//        [self.navigationController pushViewController:webVc animated:YES];
        
        [self openMemberSheet];
        
    }else if (tag == 1) {
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
            DiagramViewController *diagramVc = [[DiagramViewController alloc]init];
            diagramVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:diagramVc animated:YES];
        }
        WLog(@"图解问吧");
    }else if (tag == 2) {
        WLog(@"问吧分类");
        AnswerSortViewController *asVC = [[AnswerSortViewController alloc]init];
        asVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:asVC animated:YES];
    }else if (tag == 3) {
        WLog(@"在线约课");
        WLog(@"%@",[WShareUtil sharedData].dicSession);
        if ([WShareUtil sharedData].dicSession) {

            NSString *isgjhy =[NSString stringWithFormat:@"%@",[WShareUtil sharedData].dicSession[@"isgjhy"]];
            if ([isgjhy isEqualToString:@"0"]) {//非高级会员
                UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此功能只对高级会员开放!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [av show];
                return;
                
            }else {
                
                WWebViewController *webVc = [[WWebViewController alloc] init];
                NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"kcyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
                NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
                webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
                webVc.strTitle = @"在线约课";
                [self.navigationController pushViewController:webVc animated:YES];
            }
            
        } else {
//            [SVProgressHUD showImage:nil status:@"请先登录"];
//            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
//            [SVProgressHUD dismissWithDelay:1.];
//            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
            
            [WShareUtil sharedData].Who = @"SYZXYK";
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }
    }else if (tag == 4) {
        WLog(@"会员缴费");
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
            if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strlxmc]) {
                MemberViewController *memberVc = [[MemberViewController alloc] init];
                memberVc.title = @"会员缴费";
                [self.navigationController pushViewController:memberVc animated:YES];
            } else {
                NSString *message = [NSString stringWithFormat:@"您已经是%@",[WShareUtil sharedData].strlxmc];
                [WShareUtil showAlert:ALERT_TITLE message:message];
            }

        } 

//        NetworkPayViewController *networkPayVc = [[NetworkPayViewController alloc]init];
//        networkPayVc.title = @"会员缴费";
//        [self.navigationController pushViewController:networkPayVc animated:YES];
    }else if (tag == 5) {
        
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {
#if TARGET_IPHONE_SIMULATOR
            [WShareUtil showAlert:@"温馨提示" message:@"请用真机扫描"];
            WLog(@"run on simulator");
            return;
#define SIMULATOR_TEST
#else
            //相机权限
            AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
            if (authStatus ==AVAuthorizationStatusRestricted ||//此应用程序没有被授权访问的照片数据。可能是家长控制权限
                authStatus ==AVAuthorizationStatusDenied)  //用户已经明确否认了这一照片数据的应用程序访问
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"无法调用您的相机，是否去设置里面开启" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                alertView.tag = 600;
                [alertView show];
            } else {
                //不定义SIMULATOR_TEST这个宏
                SGQRCodeScanningVC *QRVc = [[SGQRCodeScanningVC alloc] init];
                [self.navigationController pushViewController:QRVc animated:YES];
            }
#endif
        }

    }else if (tag == 6) {
        self.tabBarController.selectedIndex = 1;
    }
}


//首页请求
- (void)hotVcDataRequestNum:(NSString *)pageNum{

    [WShareUtil sharedData].isShowWait = NO;

    NSDictionary *parametersDict;
    NSString *username;
    NSString *nologinuser;
    if ([WShareUtil sharedData].dicSession) {
        username = [WShareUtil sharedData].dicSession[@"nsrsbh"];
        if (username == nil) {
            username = @"";
        }
        parametersDict  = @{@"mode":@"native",@"service":@"init",@"content":@{@"username":username,@"screen":@"init2",@"page":pageNum,@"pagesize":@"2",@"apptype":@"ios"}};
    } else {
        nologinuser = [WShareUtil getUUID];
        parametersDict  = @{@"mode":@"native",@"service":@"init",@"content":@{@"nologinuser":nologinuser,@"screen":@"init2",@"page":pageNum,@"pagesize":@"2",@"apptype":@"ios"}};
    }
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        WLog(@"返回的(json字符串格式的)解密数据%@",returnStr);
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        sum = [NSString stringWithFormat:@"%@",returnDic[@"sum"]];

        [WShareUtil removeDataWithUserDefaultsForKey:@"newHotList"];
        [WShareUtil saveDataWithUserDefaultsSetObject:returnDic ForKey:@"newHotList"];
        
        //解析数据方法
        [self analysisDataDic:returnDic];

        isRefrsh = YES;
        if (isRefrsh) {
            lbHeadRefrsh.frame = CGRectMake(0, 0, WSCREENH_WIDTH, 35);
            NSMutableAttributedString *aString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"为您更新了%@条内容，下拉查看更多",sum]];
            [aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]range:NSMakeRange(5,aString.length - 15)];
            [aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]range:NSMakeRange(aString.length - 6,6)];

            lbHeadRefrsh.attributedText = aString;

            [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerAction) userInfo:nil repeats:NO];
        }
        [self.tableView reloadData];
        [self noWifiRefershingEnd];
    } failure:^(NSError *error) {
        lbHeadRefrsh.frame = CGRectMake(0, 0, WSCREENH_WIDTH, 0);
        self.tableView.tableHeaderView = lbHeadRefrsh;
        [self noWifiRefershingEnd];
        WLog(@"失败");
    } showProgress:YES];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if (alertView.tag == 600) {
        if (buttonIndex == 1) {
            // 无权限 引导去开启
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
        }
    }
}

- (void)hotVcDataRequestStrNum:(NSString *)pageNum isRefrsh:(BOOL)isRefrsh{

    [WShareUtil sharedData].isShowWait = NO;

    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"sxfw",@"content":@{@"revert":@"sxbbpage",@"pagesize":@"10",@"pagenumber":pageNum,@"apptype":@"ios"}};

    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        WLog(@"返回的(json字符串格式的)解密数据%@",returnStr);
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        if (isRefrsh) {
            [self.arrRecom removeAllObjects];
        }
        for (NSDictionary *dic in returnDic[@"data"]) {
            HotRecomModel *hotRecomModel = [HotRecomModel mj_objectWithKeyValues:dic];
            WLog(@"%@============",hotRecomModel.strId);
            [self.arrRecom addObject:hotRecomModel];
        }

        NSMutableArray *recomIdArray = [[NSMutableArray alloc] init];
        NSMutableArray *hotRecomArray = [[NSMutableArray alloc] init];
        for (HotRecomModel *hotRecomModel in self.arrRecom){
            if (![recomIdArray containsObject:hotRecomModel.strId]){
                [recomIdArray addObject:hotRecomModel.strId];
                [hotRecomArray addObject:hotRecomModel];
            }
        }

        [self.arrRecom removeAllObjects];
        [self.arrRecom addObjectsFromArray:hotRecomArray];

        [self.tableView reloadData];

        if (self.arrRecom.count < 10) {
            // 拿到当前的上拉刷新控件，变为没有更多数据的状态
            [self.tableView.footer endRefreshingWithNoMoreData];
        }

        [self noWifiRefershingEnd];

    } failure:^(NSError *error) {
        [self noWifiRefershingEnd];
        WLog(@"失败");
    } showProgress:YES];
}

- (void)openMemberSheet {
    
    bgMebemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT)];
    bgMebemView.backgroundColor = WRGBAColor(0, 0, 0, 0.5);
    //    [self.view addSubview:bgMebemView];
    
    viewContent = [[UIView alloc] initWithFrame:CGRectMake((WSCREENH_WIDTH - 280) * 0.5, (WSCREENH_HEIGHT - 240) * 0.5, 280, 200)];
    viewContent.backgroundColor = WRGBColor(255, 255, 255);
    viewContent.layer.cornerRadius = 10;
    
    UILabel *lbTit = [[UILabel alloc] initWithFrame:CGRectMake(15, 12, 280-30, 50)];
    lbTit.backgroundColor = [UIColor whiteColor];
    lbTit.text = @"请根据您要咨询的问题，选择对应的问题类型";
    lbTit.font = [UIFont systemFontOfSize:15];
    lbTit.textAlignment = NSTextAlignmentCenter;
    lbTit.numberOfLines = 0;
    [viewContent addSubview:lbTit];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 70, 280, 1)];
    lineView.backgroundColor = WRGBColor(243, 243, 243);
    [viewContent addSubview:lineView];
    
    UIButton *btnMember = [[UIButton alloc] initWithFrame:CGRectMake(0, 70, 280, 44)];
    [btnMember.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnMember setTitle:@"防伪开票" forState:UIControlStateNormal];
    [btnMember setTitleColor:[UIColor colorWithRed:0 green:0.6 blue:0.92 alpha:1] forState:UIControlStateNormal];
    btnMember.tag = 100;
    [btnMember addTarget:self action:@selector(btnOpenClick:) forControlEvents:UIControlEventTouchUpInside];
    [viewContent addSubview:btnMember];
    
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 113, 280, 1)];
    lineView1.backgroundColor = WRGBColor(243, 243, 243);
    [viewContent addSubview:lineView1];
    
    UIButton *btnTourist = [[UIButton alloc] initWithFrame:CGRectMake(0, 114, 280, 44)];
    [btnTourist.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnTourist setTitle:@"申报、认证等其他" forState:UIControlStateNormal];
    [btnTourist setTitleColor:[UIColor colorWithRed:0 green:0.6 blue:0.92 alpha:1] forState:UIControlStateNormal];
    btnTourist.tag = 110;
    [btnTourist addTarget:self action:@selector(btnOpenClick:) forControlEvents:UIControlEventTouchUpInside];
    [viewContent addSubview:btnTourist];
    
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 157, 280, 1)];
    lineView2.backgroundColor = WRGBColor(243, 243, 243);
    [viewContent addSubview:lineView2];
    
    UIButton *btnLogin = [[UIButton alloc] initWithFrame:CGRectMake(0, 158, 280, 44)];
    [btnLogin.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnLogin setTitle:@"取消" forState:UIControlStateNormal];
    [btnLogin addTarget:self action:@selector(btnOpenClick:) forControlEvents:UIControlEventTouchUpInside];
    btnLogin.tag = 120;
    [btnLogin setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [viewContent addSubview:btnLogin];
    
    [bgMebemView addSubview:viewContent];
    [[[UIApplication sharedApplication] delegate].window addSubview:bgMebemView];
    
}

- (void)btnOpenClick:(UIButton *)btn {
    if (btn.tag == 100) {
        
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"开票客服";
        webVc.strUrl = @"http://www.sobot.com/chat/pc/index.html?sysNum=79f43fe7ebd049898175758d0b00d986";
        [self.navigationController pushViewController:webVc animated:YES];
        
    } else if (btn.tag == 110) {
        
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"申报认证客服";
        webVc.strUrl = @"https://www.sobot.com/chat/h5/index.html?sysNum=f6a79964432e4eb1b2f70f92a6dfcbe4";
        [self.navigationController pushViewController:webVc animated:YES];
        
    } else {
        
    }
    [bgMebemView removeFromSuperview];
    [viewContent removeFromSuperview];
}

- (void)requestWdjf{

    NSDictionary *parametersDict;
    NSString *nologinuser;
    if ([WShareUtil sharedData].dicSession) {
        parametersDict = @{@"content":@{@"revert":@"basic",@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]},@"mode":@"native",@"service":@"mine"};
    } else {
        nologinuser = [WShareUtil getUUID];
        parametersDict = @{@"content":@{@"revert":@"basic",@"nologinuser":nologinuser},@"mode":@"native",@"service":@"mine"};
    }
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};

    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];

        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        WLog(@"返回的(json字符串格式的)解密数据%@",returnStr);
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        if ([successStr isEqualToString:@"false"]) {
            [WShareUtil sharedData].strRemaining = @"0.0";
            [WShareUtil sharedData].strlxmc = @"";
            return;
        }

        [WShareUtil sharedData].strRemaining = returnDic[@"remaining"];
        [WShareUtil sharedData].strlxmc = returnDic[@"lxmc"];

    } failure:^(NSError *error) {
        WLog(@"失败");
    } showProgress:YES];
}

// 解析数据方法
- (void)analysisDataDic:(NSDictionary *)returnDic{

    [WShareUtil sharedData].arrayOfAds = returnDic[@"lbt"];

    [self.arrRecom removeAllObjects];
    for (NSDictionary *dic in returnDic[@"rdtj"]) {
        HotRecomModel *hotRecomModel = [HotRecomModel mj_objectWithKeyValues:dic];
        WLog(@"%@============",hotRecomModel.strTitle);
        [self.arrRecom addObject:hotRecomModel];
    }

    [self.arrWbtop removeAllObjects];
    for (NSDictionary *dic in returnDic[@"wbtop"]) {
        WbTopModel *wbModel = [WbTopModel mj_objectWithKeyValues:dic];
        [self.arrWbtop addObject:wbModel];
    }

    [self.arrXttop removeAllObjects];
    for (NSDictionary *dic in returnDic[@"xttop"]) {
        WbTopModel *xtModel = [WbTopModel mj_objectWithKeyValues:dic];
        [self.arrXttop addObject:xtModel];
    }

    [self.arrSxbb removeAllObjects];
    for (NSDictionary *dic in returnDic[@"sxbb"]) {
        HotSxbbModel *sxbbModel = [HotSxbbModel mj_objectWithKeyValues:dic];
        [self.arrSxbb addObject:sxbbModel];
    }

    [self.arrLbt removeAllObjects];
    for (NSDictionary *dic in returnDic[@"lbt"]) {
        HotLbtModel *lbtModel = [HotLbtModel mj_objectWithKeyValues:dic];
        [self.arrLbt addObject:lbtModel];
    }

    [self.arrTop removeAllObjects];
    for (NSDictionary *dic in returnDic[@"top"]) {
        WbTopModel *topModel = [WbTopModel mj_objectWithKeyValues:dic];
        [self.arrTop addObject:topModel];
    }

    [self.arrWbdt removeAllObjects];
    for (NSDictionary *dic in returnDic[@"wbdt"]) {
        WbTopModel *wbdtModel = [WbTopModel mj_objectWithKeyValues:dic];
        [self.arrWbdt addObject:wbdtModel];
    }

}

@end
